Skip to content

fix: Index.fts({ withPosition: true }) to enable phrase queries#404

Open
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
jlin53882:fix/fts-withposition-bug-402-clean
Open

fix: Index.fts({ withPosition: true }) to enable phrase queries#404
jlin53882 wants to merge 1 commit intoCortexReach:masterfrom
jlin53882:fix/fts-withposition-bug-402-clean

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Fixes a critical bug where phrase queries (e.g., "hello world") fail with: position is not found but required for phrase queries

Root Cause

In src/store.ts, createFtsIndex() was calling Index.fts() without arguments:

config: (lancedb as any).Index.fts(),

@lancedb/lancedb Index.fts() accepts an options object, not positional boolean:

// indices.js
static fts(options) {
    return new Index(native_1.Index.fts(
        options?.withPosition,  // undefined when called with Index.fts(true)
        ...
    ));
}

When called as Index.fts(true) (boolean), options?.withPosition is undefined → phrase queries fail.

Fix

config: (lancedb as any).Index.fts({ withPosition: true }),

Verification

Tested in isolated environment (test-pr354) — 30 iterations, 150 test cases:

  • Index.fts() without args: phrase query FAILS
  • Index.fts({ withPosition: true }): phrase query PASSES 100%

Related Issue

Fixes #402

Fix BM25 search failure: position is not found but required for phrase queries

Root cause: Index.fts() accepts an options object, not a boolean.
Index.fts(true) sets options=true, so options?.withPosition is undefined.

Fix: use Index.fts({ withPosition: true }) instead.

Fixes: CortexReach#402
@jlin53882
Copy link
Copy Markdown
Contributor Author

CI 分析:此 PR 的 FTS 修正與 CI 失敗無關

CI 失敗的真正原因

本次 CI 失敗的是 cli-smoke job 中的 plugin-manifest-regression.test.mjs 測試,錯誤位於第 155 行:

AssertionError [ERR_ASSERTION]: sessionMemory should stay disabled by default
+ actual - expected
+ [AsyncFunction: appendSelfImprovementNote]
- undefined

這是 upstream master 分支的 selfImprovement regression bug,與本 PR 修改的 src/store.ts FTS index 建立邏輯完全無關。

觸發原因

測試 config 為 { autoRecall: false, embedding: {...} }(無 selfImprovement block)。

Upstream master 最近有兩個 commit 造成 regression:

Commit 內容
fix: default selfImprovement.enabled to true when config block omitted... 將 selfImprovement.enabled 預設值改為 true,但實作有 bug
fix: use native fetch for Ollama embedding... 同時也造成 CI 失敗

當 selfImprovement.enabled 預設為 true 時,appendSelfImprovementNote 被錯誤地當作 command:new hook 註冊,導致 assertion api.hooks["command:new"] === undefined 失敗。

upstream master 的 CI 狀態

master 分支本身的 CI 也處於 failed 狀態(最近兩次 push 都是 failed),確認這是既有問題,不是本 PR 引入的。

本 PR 的變更確認

  • 變更檔案src/store.ts(1 行)
  • 變更內容Index.fts()Index.fts({ withPosition: true })
  • 目的:修復 phrase query 所需的 position 資料
  • 驗證:在 test-pr354 隔離環境中 30 次迭代、150 個測試 case,100% 成功
  • 與 CI 失敗的關聯性:無(隔離且最小變更)

建議

等待 upstream maintainer 修復 master 的 selfImprovement regression 後,本 PR 即可合併。

@jlin53882
Copy link
Copy Markdown
Contributor Author

Note: The CI failure is caused by a separate regression bug tracked in #405.

This PR (#404) only fixes the FTS phrase query bug in src/store.ts. The CI failure is unrelated to this fix.

Copy link
Copy Markdown
Collaborator

@AliceLJY AliceLJY left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One-line fix, root cause is clear. CI failure is unrelated (#405). LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] BM25 search fails: position is not found but required for phrase queries

3 participants